﻿<%@ Page Title="Editar secuencia de estados" Language="C#" MasterPageFile="~/Site.Master"
	AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="TraceThisItem.WebUI.Workflows.Edit" %>

<%@ Register Src="~/UserControls/WorkflowEditor.ascx" TagPrefix="uc" TagName="WorkflowEditor" %>
<asp:Content ID="Head" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Body" ContentPlaceHolderID="MainContent" runat="server">
	<asp:HiddenField ID="CanEdit" runat="server" Value="1" />
	<div class="failureNotification">
		<asp:Literal ID="litMessage" runat="server" />
	</div>
	<asp:ValidationSummary ID="Errors" runat="server" CssClass="failureNotification" />
	<h1>
		Flujo&nbsp;<asp:Literal ID="litWfName" runat="server" />
	</h1>
	<asp:Panel ID="DistributionSection" runat="server" GroupingText="Distribución">
		<asp:GridView Id="EditorGrid" runat="server"  Width="75%"
			onrowdatabound="EditorGrid_RowDataBound" AutoGenerateColumns="False" 
			DataSourceID="StatusNodesDataSource" DataKeyNames="Id" 
			onrowediting="EditorGrid_RowEditing" onrowupdating="EditorGrid_RowUpdating" 
			onrowcommand="EditorGrid_RowCommand" EmptyDataText="No hay estados que ordenar">						
			<Columns>
				<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" ReadOnly="true" />
				<asp:BoundField DataField="Name" HeaderText="Nodo" SortExpression="Name" />
				<asp:TemplateField HeaderText="Siguientes nodos" 
					SortExpression="NextStatusNodesNames">
					<ItemTemplate>
						<asp:Label ID="Label1" runat="server" 
							Text='<%# Bind("NextStatusNodesNames") %>'></asp:Label>
					</ItemTemplate>
					<EditItemTemplate>
						<asp:ListBox ID="NextPossibleStatusNodes" runat="server" DataSourceID="NextPossibleStatusNodesDataSource" 
							DataTextField="Name" DataValueField="Id" Width="225px" 
							ondatabinding="NextPossibleStatusNodes_DataBinding" 
							ondatabound="NextPossibleStatusNodes_DataBound" SelectionMode="Multiple">
						</asp:ListBox>
					</EditItemTemplate>
				</asp:TemplateField>
				<asp:CommandField ShowEditButton="True" />
			</Columns>
		</asp:GridView>		
	</asp:Panel>
	<asp:Panel ID="NewNodeSection" runat="server" GroupingText="Agregar nuevo nodo">
		<asp:Label ID="Label1" Text="Nombre del nodo:" runat="server" AssociatedControlID="NewStatusNodeName" />
		<asp:TextBox ID="NewStatusNodeName" runat="server" ValidationGroup="AddNewNode" />
		<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="El nombre del nuevo nodo es obligatorio"
			ControlToValidate="NewStatusNodeName" runat="server" ValidationGroup="AddNewNode"
			CssClass="failureNotification" ToolTip="El nombre del nuevo nodo es obligatorio">*</asp:RequiredFieldValidator>
		<asp:Button ID="btnAddNewNode" Text="Agregar" runat="server" ValidationGroup="AddNewNode"
			OnClick="btnAddNewNode_Click" />
	</asp:Panel>
	<asp:Panel ID="RemoveNodeSection" runat="server" GroupingText="Remover nodo">
		<asp:Label ID="Label2" Text="Nombre del nodo:" runat="server" AssociatedControlID="CurrentNodes" />
		<asp:DropDownList ID="CurrentNodes" runat="server" 
			DataSourceID="RemoveStatusNodesDataSource" DataTextField="Name" DataValueField="Id">
			<asp:ListItem Text="(No hay nodos definidos)" />
		</asp:DropDownList>
		<asp:Button ID="btnRemove" Text="Remover" runat="server" 
			onclick="btnRemove_Click" />
	</asp:Panel>
	
	<asp:ObjectDataSource ID="StatusNodesDataSource" runat="server" 
		OldValuesParameterFormatString="original_{0}" 
		onobjectcreating="StatusNodesDataSource_ObjectCreating" 
		SelectMethod="GetStatusNodesByWorkFlow" TypeName="TraceThisItem.Domain.Facade" 
		DataObjectTypeName="TraceThisItem.Domain.StatusNode" 
		UpdateMethod="UpdateStatusNode">
		<SelectParameters>
			<asp:QueryStringParameter Name="workflowId" QueryStringField="id" 
				Type="Int32" />
		</SelectParameters>
	</asp:ObjectDataSource>
	<asp:ObjectDataSource ID="RemoveStatusNodesDataSource" runat="server" 
		OldValuesParameterFormatString="original_{0}" 
		onobjectcreating="StatusNodesDataSource_ObjectCreating" 
		SelectMethod="GetStatusNodesByWorkFlow" TypeName="TraceThisItem.Domain.Facade" 
		DataObjectTypeName="TraceThisItem.Domain.StatusNode" 
		UpdateMethod="UpdateStatusNode">
		<SelectParameters>
			<asp:QueryStringParameter Name="workflowId" QueryStringField="id" 
				Type="Int32" />
		</SelectParameters>
	</asp:ObjectDataSource>
	<asp:ObjectDataSource ID="NextPossibleStatusNodesDataSource" runat="server" 
		OldValuesParameterFormatString="original_{0}" 
		SelectMethod="GetNextPossibleStatusNodesByWorkFlowAndCurrentStatusNode" 
		TypeName="TraceThisItem.Domain.Facade" 
		onobjectcreating="StatusNodesDataSource_ObjectCreating">
		<SelectParameters>
			<asp:QueryStringParameter Name="workflowId" QueryStringField="id" 
				Type="Int32" />
			<asp:ControlParameter ControlID="EditorGrid" Name="currentStatusNodeId" 
				PropertyName="SelectedValue" Type="Int32" />
		</SelectParameters>
	</asp:ObjectDataSource>
</asp:Content>

